package config

import (
	"fmt"
	"github.com/spf13/viper"
	"log"
)

func LoadConfig(path, name, configType string) {
	viper.SetConfigName(name)
	viper.SetConfigType(configType)
	viper.AddConfigPath(path)

	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("fatal error config file: %w", err))
	}
}

func ParseConfig(config interface{}) interface{} {
	err := viper.Unmarshal(config)
	if err != nil {
		log.Fatalf("unable to decode into struct, %v", err)
	}
	return config
}
